/*LICENSE_BEGIN
 * ******************************************************************
 * Copyright 2006 by the Dainamite Robocup-Team at the
 * DAI-Labor, TU-Berlin (www.dai-labor.de)
 * 
 * Members of Dainamite are:
 * Holger Endert
 * Robert Wetzker
 * Thomas Karbe
 * Axel Heßler
 * Philippe Bütter
 * Felix Brossmann
 * 
 * Licensed under the GNU GPL (General Public License) Free Software 
 * License, Version 2. You may use this file only in compliance with 
 * the License. You may obtain a copy of the License at:
 * 
 * http://www.fsf.org/licensing/licenses/gpl.txt
 * ******************************************************************
LICENSE_END*/
package robocup.component.actions;

import robocup.component.math.RCMath;

/**
 * A turn neck action is used to turn the head into a different direction. 
 * Using this, the agent can see other objects than those lying in fron of him.
 * The maximum angle can be at most [-90,90] degree relative to the players 
 * body direction (else its neck is broken :-)
 */
public class TurnNeckAction extends Action {

	/**
	 * The angle can be a value of [-180,180], but should not result in higher 
	 * values of [-90,90] relative to the body angle.
	 */
	private double _angle;

	/**
	 * Constructor - an action for turning the head direction
	 * 
	 * @param angle
	 *            the angle to turn (-180, 180]
	 */
	public TurnNeckAction(double angle) {
		this._angle = RCMath.round(angle, Action.PARAMETER_PRECISION);
		this._type = TYPE.TURN_NECK;
	}

	/**
	 * Returns the actions string representation:
	 * @return 
	 * (turn_neck &lt;angle&gt;)<br><br>
	 */
	@Override
	public String toString() {
		StringBuffer buf = new StringBuffer();
		buf.append("(turn_neck ");
		buf.append(this._angle);
		buf.append(")");
		return buf.toString();
	}

	/**
	 * @return Returns the angle.
	 */
	public double getAngle() {
		return this._angle;
	}

	/**
	 * An action is worth sending if it effects the world.
	 * @return Returns true, if the angle is not equal to zero.
	 */
	@Override
	public boolean isWorthSending() {
		return !(this._angle == 0);
	}

	/**
	 * Sets a new angle to the command.
	 * @param _angle - the new angle
	 */
	public void setAngle(double _angle) {
		this._angle = _angle;
	}

}
